package org.vaadin.nf4v.ext.runtime.menu.menubar;

import com.vaadin.ui.MenuBar;
import org.vaadin.nf4v.core.navigation.NavigationManager;
import org.vaadin.nf4v.ext.config.menu.MenuItemDescription;

/**
 * Menu command.
 * Executes navigation to target page.
 */
public class NavigationCommand implements MenuBar.Command {
    private MenuItemDescription description;

    public NavigationCommand(MenuItemDescription description) {
        this.description = description;
    }

    @Override
    public void menuSelected(MenuBar.MenuItem selectedItem) {
        if (description.isContextSensitive()) {
            NavigationManager.navigateTo(description.getConfig().getPageClass());
        } else {
            NavigationManager.navigateTo(description.getContext(), description.getConfig().getPageClass());
        }
    }
}
